import jdk.internal.org.objectweb.asm.tree.analysis.Value;

import java.util.ArrayList;
import java.util.List;

import static java.util.Collections.swap;

public class Heap {
    private List<ValueIndex> heap;
    int max;

    public Heap(int max) {
        this.max = max + 1;
    }

    public void insert(double value, int index) {
        if (heap.size() == 0)
            heap.add(new ValueIndex(0.0, 0));
        heap.add(new ValueIndex(value, index));
        heapUp(heap.size() - 1);
        if (heap.size() > max) {
            heap.remove(max);
        }
    }

    public int[] getValue() {
        int[] result = new int[max - 1];
        for (int i = 1; i < max; ++i) {
            result[i - 1] = heap.get(i).index;
        }
        return result;
    }

    public void heapUp(int index) {
        if (index > 1) {
            int parent = index / 2;
            double parentValue = heap.get(parent).value;
            double indexValue = heap.get(index).value;
            if (parentValue < indexValue) {
                swap(heap, parent, index);
                heapUp(parent);
            }

        }
    }
}


class ValueIndex {
    public double value;
    public int index;

    public ValueIndex(double value, int index) {
        this.value = value;
        this.index = index;
    }
}
